#coding=utf-8

from selenium import webdriver
from appium import webdriver
from time import sleep
from selenium.common.exceptions import WebDriverException
import os
from nav_plugin_op import nav_plugin_factory
from Public import BasePage
from Public import BaseConstant
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from Public import BaseConstant

#实例化基础数据
navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
basicAction = BasicAction()
Messagebar_Paramter_instances = BaseConstant.Messagebar_Paramter
#nav_name = "消息"
nav_name = ["导航栏消息",'xpath',"//android.widget.LinearLayout[@resource-id='cn.com.egova.egovamobile:id/base_tab_tabs_bottom']/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RadioButton[1]"]
case_click_name = "上报时间"
finish_case_name = "办结"

class message_bar_factory():

	def viwe_case_assistant(self,driver,file_path):
		try:
			# 点击消息的导航，打开消息列表
			# nav_plugin_factory.nav_open(navOpenFactory,nav_name.decode("utf-8"),driver)
			element_oprate_instance.element_click(nav_name,file_path)
			# 点击"案件处置助手
			if element_oprate_instance.element_display_commit(Messagebar_Paramter_instances.case_assistant_name, file_path):
				element_oprate_instance.element_click(Messagebar_Paramter_instances.case_assistant_name,file_path)
				sleep(5)
				# driver.find_element_by_name(case_click_name.decode("utf-8")).click()
				# sleep(2)
				element_oprate_instance.element_save_pic(file_path, '/viwe_case_assistant_successful')
				element_oprate_instance.element_click(Messagebar_Paramter_instances.exit_id, file_path)
				# driver.find_element_by_id(exit_id).click()
			else:
				print 'test case_assistant failed'
				raise

		except WebDriverException,el_error:
			element_oprate_instance.element_save_pic(file_path, '/ viwe_case_assistant_fail')
			print el_error
			return False

	def viwe_my_task(self,driver,file_path):
		try:
			if element_oprate_instance.element_display_commit(Messagebar_Paramter_instances.my_task_name, file_path):
				element_oprate_instance.element_click(Messagebar_Paramter_instances.my_task_name,file_path)
				sleep(5)
				element_oprate_instance.element_save_pic(file_path, '//viwe_my_task_successful')
				element_oprate_instance.element_click(Messagebar_Paramter_instances.exit_id, file_path)
			else:
				print 'test my_task failed'
				raise

		except WebDriverException,el_error:
			element_oprate_instance.element_save_pic(file_path, '//viwe_my_task_fail')
			print el_error
			return False

	def viwe_leader_assign(self,driver,file_path):
		try:
			if element_oprate_instance.element_display_commit(Messagebar_Paramter_instances.leader_assign_name, file_path):
				element_oprate_instance.element_click(Messagebar_Paramter_instances.leader_assign_name,file_path)
				driver.implicitly_wait(15)
				element_oprate_instance.element_save_pic(file_path, '//viwe_leader_assign_successful')
				element_oprate_instance.element_click(Messagebar_Paramter_instances.exit_id, file_path)
			else:
				print 'test leader_assign failed'

		except WebDriverException,el_error:
			element_oprate_instance.element_save_pic(file_path, "//viwe_leader_assign_fail")
			print el_error
			return False

if __name__ == '__main__':
    print u'test'